https://linen.dev logo
Difficulty adding custom tools to CrewAI provider
# 🖥│support-forum
k
Hello! I have a setup where I'm trying to use prebuilt and custom tools together with a crewAi agent. I'm having trouble getting to recognize the custom tools and I've tried several different approaches from the documentation.
Copy code
composio = Composio(api_key=api_key, provider=CrewAIProvider())

class GetTaskCommentsInput(BaseModel):
    task_id: str = Field(..., description="Task ID to retrieve comments for")

@composio.tools.custom_tool(toolkit="asana")
def get_task_comments(
    request: GetTaskCommentsInput,
    execute_request: ExecuteRequestFn,
    auth_credentials: dict,
) -> dict:
    """Gather comments for a particular task."""
    res = execute_request(
        endpoint=f"tasks/{request.task_id}/stories/",
        method="GET"
    )
    return {"comments": json.dumps(res, indent=4)}

# I've tried:
tools = [get_task_comments]
tools = [composio.tools.get(user_id=user_id, tools=[get_task_comments.slug])
tools = [composio.tools.get(user_id=user_id, slug=get_task_comments.slug)

Agent(
        role="",
        goal="""
        """,
        backstory=(
            ""
        ),
        verbose=True,
        tools=tools,
        allow_delegation=True,
        llm=ChatOpenAI(model_name="gpt-4.1"),
    )
However the agent can work with builtin tools but not with these custom tools. It may call them and then leave an error that the tool is not found.
c
Hi Kevin, Could you share your SDK version? It will help us in debugging. Thanks!
Also, I've noticed a few issues with your snippet. Could you please fix them? 1. Update your endpoint with
base_url
, this is how it should look like: /endpoint... 2. The Tool Slug should be
ASANA_GET_TASK_COMMENTS
. 3. Please pass Authorization headers. You can refer this example: Let me know if this works. Latest SDK version:
pip install composio-crewai==0.8.5
,
pip install composio==0.8.5
k
Here's what I have installed. composio==0.8.5 composio-client==1.6.0 composio-crewai==0.8.5 composio_core==0.7.20 composio_langchain==0.7.20 Thanks, yes I've made the requested updates. These are all issues that happen once the tool is called, however, and I'm having trouble with the tool being called. get_task_comments.slug == 'ASANA_GET_TASK_COMMENTS' as I'm seeing it but the problem does seem to be related to the name. This is the error I'm seeing when the agent tries to call the tool. > I encountered an error while trying to use the tool. This was the error: Error code: 404 - {'error': {'message': 'Tool GET_TASK_COMMENTS not found', 'code': 2401, 'status': 404, 'request_id': '2a53614fe9124de2b936199807ebf21c', 'suggested_fix': 'Check if the tool exists.'}}. > Tool GET_TASK_COMMENTS accepts these inputs: Tool Name: GET_TASK_COMMENTS > Tool Arguments: {'task_id': {'description': 'Task ID to retrieve comments for. Please provide a value of type string. This parameter is required.', 'type': 'str'}} > Tool Description: Gather comments for a particular task.
c
Did you get a chance to try the suggested changes?
k
Yes, I see the error I mentioned above with the suggested changes.
c
The above error suggests the Tool Slug is still
GET_TASK_COMMENTS
, Could you please try
ASANA_GET_TASK_COMMENTS
. Also, pass the task Id as a string instead of an inteager.
k
What is the appropriate way to add custom tools to the crewai agent? When I run composio.tools.get( user_id=enterprise_id, tools=['ASANA_GET_TASK_COMMENTS'] ) I get back a Wrapper that looksl ike it has the wrong name: > name='GET_TASK_COMMENTS' description="Tool Name: GET_TASK_COMMENTS\nTool Arguments: {'task_id': {'description': 'Task ID to retrieve comments for. Please provide a value of type string. This parameter is required.', 'type': 'str'}}\nTool Description: Gather comments for a particular task." env_vars=[] args_schema= description_updated=False cache_function=<function BaseTool. at 0x10fc92520> result_as_answer=False max_usage_count=None current_usage_count=0
It's looking to me that there's a bug in the Composio code for custom tools. In the init method https://github.com/ComposioHQ/composio/blob/653bef7ae4b456dd698cd618f66ba75f64668a7e/python/composio/core/models/custom_tools.py#L75 the name and slug are updated but self.info is not updated. So this still has the name without the prepended toolkit.
There's ALSO a bug where the user_id passed to custo tools is ALWAYS default. This can cause some pretty major security issues if the wrong account is accessed. I fixed the first issue with this before kicking off my crew.
Copy code
for key, val in composio.tools._custom_tools.custom_tools_registry.items():
        val.info.slug = val.slug
        val.info.name = val.name
and the second issue by injecting the user id into the parameters before the tool call.
Copy code
@before_execute(tools=["ASANA_GET_TASK_COMMENTS"])
def inject_user_id(
    tool: str,
    toolkit: str,
    params: ToolExecuteParams
) -> dict:
    params['arguments']['user_id'] = params['user_id']
    return params
a
Hey @kevinjohnson_08279, thank you for flagging these! I'd really appreciate if you could create GitHub issues for the same 🙂